import axios from 'axios'

// create an axios instance
const service = axios.create({
  baseURL: 'http://localhost:3000', // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// 添加响应拦截器
service.interceptors.response.use(function(response) {
  // 对响应数据做点什么
  if (!response.data.success) {
    return Promise.reject(new Error(response.data))
  }
  return response
}, function(error) {
  // 对响应错误做点什么
  return Promise.reject(error)
})

export default service
